﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MS.InformationManagement.DAL.DocumentCenter;
using Microsoft.SharePoint;
using MS.InformationManagement.Core.SystemUser;

namespace MS.InformationManagement.BLL.UserManagement
{
    public class UsersManagement
    {

        #region Public Methods

        public IEnumerable<UsuarioSistema> GetAllSystemUsers()
        {
            using (var dc = new DCDocumentCenterDataContext(SPContext.Current.Web.Url))
            { 
                var users =(from user in dc.UsuariosDelSistema
                            orderby user.Usuario descending
                            select user);
                return users;
            }
        }

        public void CreateUsers(SPFieldUserValueCollection users, Dictionary<string,Object> Properties)
        {
            foreach (SPFieldUserValue user in users)
            {
                if (!UsersManager.UserExists(user) && !UsersManager.DocumentLibraryUserExists(user))
                {
                    UsersManager.AddUser(user);
                    Guid libraryUser = UsersManager.CreateDocumentLibrary(user);
                    UsersManager.SetNewUserPermissions(user, libraryUser);
                }

                UsersManager.UpdateUserProfileProperties(user.User.LoginName, Properties); 
            }
        }

        #endregion

    }
}
